<?php

if (!defined('NV_ADMIN')) {
    die ("Access Denied");
}

$aid = trim($aid);
$sql = "select radminsuper from ".$prefix."_authors where aid='$aid'";
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$radminsuper = $row[radminsuper];
if ($radminsuper==1) {

##################################################
# ADD MANAGER																		 #
##################################################

function quangcaoquanly() {
global $adminfile, $prefix, $db, $multilingual, $bgcolor2, $Home_Module;

    include ("../header.php");
    GraphicAdmin();
    
    OpenTable();
    echo "<center><font class=\"title\"><b>QUẢN LÝ QUẢNG CÁO</b></font></center>";
    CloseTable();
    OpenTable();
	echo "<center><font class=\"title\"><b>TẤT CẢ CÁC QUẢNG CÁO LIÊN KẾT</b></font><br><br><table border=\"1\" width=\"100%\" bgcolor=\"$bgcolor1\">"
	."<tr><td bgcolor=\"$bgcolor2\" align=\"center\"><b>TT</b></td>"
	."<td bgcolor=\"$bgcolor2\" align=\"center\"><b>TÊN WEBSITE</b></td>"
	."<td bgcolor=\"$bgcolor2\" align=\"center\">&nbsp;<b>URL CỦA WEBSITE</b>&nbsp;</td>"
	."<td bgcolor=\"$bgcolor2\" align=\"center\" nowrap>&nbsp;<b>ĐƯỜNG DẪN HÌNH LOGO CỦA WEBSITE</b>&nbsp;</td>"
	."<td bgcolor=\"$bgcolor2\" align=\"center\" nowrap>&nbsp;<b>Vị trí quảng cáo</b>&nbsp;</td></tr>";
	
    $sql = "select quangcao_id, quangcao_web, quangcao_url, quangcao_img, quangcao_type from ".$prefix."_quangcao";
    $result = $db->sql_query($sql);
    while($row = $db->sql_fetchrow($result)) {
    $quangcao_id = $row[quangcao_id];
    $quangcao_web = $row[quangcao_web];
    $quangcao_url = $row[quangcao_url];
    $quangcao_img = $row[quangcao_img];
   	$quangcao_type = $row[quangcao_type];
   	
	echo "<tr><td align=\"right\" bgcolor=\"$bgcolor3\"><b>$quangcao_id</b>"
	    ."</td><td align=\"left\" width=\"100%\" bgcolor=\"$bgcolor3\"><b>$quangcao_web</b>"
	    ."</td><td align=\"center\" bgcolor=\"$bgcolor3\">$quangcao_url"
	    ."</td><td align=\"center\" nowrap bgcolor=\"$bgcolor3\">$quangcao_img"
	    ."</td><td align=\"center\" nowrap bgcolor=\"$bgcolor3\">$quangcao_type"
	    ."</td><td align=\"right\" nowrap bgcolor=\"$bgcolor3\">(<a href=\"".$adminfile.".php?op=quangcaoedit&quangcao_id=$quangcao_id\">"._EDIT."</a>-<a href=\"".$adminfile.".php?op=quangcaodel&quangcao_id=$quangcao_id\">"._DELETE."</a>)"
	    ."</td></tr>";
  }
  echo "</table></center><br>"   
  ."<form action=\"".$adminfile.".php\" method=\"POST\"><table><tbody><tr><td colspan=\"2\" class=\"title\" align=\"center\">Thêm Liên kết</td></tr><tr><td class=\"fr\" width=\"30%\"><b>Tên Web</b></td><td class=\"fr_2\"><input name=\"webname\" size=\"50\" value=\"\" type=\"text\"></td></tr><tr><td class=\"fr\" width=\"30%\"><b>Link</b></td><td class=\"fr_2\"><input name=\"weburl\" size=\"50\" value=\"\" type=\"text\"></td></tr><tr><td class=\"fr\" width=\"30%\"><b>Logo</b></td><td class=\"fr_2\"><input name=\"webimg\" size=\"50\" value=\"\" type=\"text\"></td></tr>"
  ."<tr><td class=\"fr\" width=\"30%\"><b>Vị trí quảng cáo</b></td><td class=\"fr_2\">"
  ."<select name=\"quangcaotype\">"
  ."<option value=\"\">Vị trí:</option>\n"
  ."<option value=\"1\">Trong block</option>\n"
  ."<option value=\"2\">Bên trái</option>\n"
  ."<option value=\"3\">Bên phải</option>\n"
  ."</td></tr><tr><td class=\"fr\" colspan=\"2\" align=\"center\">"
  ."<input type=\"hidden\" name=\"op\" value=\"quangcaoadd\">"
	."<input type=\"submit\" value=\"THÊM LIÊN KẾT\">"
  ."</td></tr></tbody></table></form>\n";
  CloseTable();
  
include("../footer.php");
}



##################################################
# ADD ADS																			   #
##################################################

function quangcaoadd($webname, $weburl, $webimg,$quangcaotype) {
    global $adminfile, $prefix, $db;
    
    $webname = stripslashes(FixQuotes($webname));
    $weburl = stripslashes(FixQuotes($weburl));
    $webimg = stripslashes(FixQuotes($webimg));
    $quangcaotype = intval($quangcaotype);
    
    $db->sql_query("insert into ".$prefix."_quangcao values (NULL, '$webname', '$weburl', '$webimg', '$quangcaotype')");
    
    if (!$db) {
	exit();
    }
    
    Header("Location: ".$adminfile.".php?op=quangcaoquanly");
}

##################################################
# EDIT ADS																			 #
##################################################

function quangcaoedit($quangcao_id){
    global $editor, $adminfile, $admin, $prefix, $db, $multilingual;
    
    include ("../header.php");
    GraphicAdmin();
    
    OpenTable();
    echo "<center><font class=\"title\"><b>SỬA QUẢNG CÁO LIÊN KẾT</b></font></center>";
    CloseTable();
    echo "<br>";
    $quangcao_id = intval($quangcao_id);
    $sql = "select quangcao_web, quangcao_url, quangcao_img, quangcao_type from ".$prefix."_quangcao WHERE quangcao_id='$quangcao_id'";
    $result = $db->sql_query($sql);
    $row2 = $db->sql_fetchrow($result);
    $quangcao_web = $row2[quangcao_web];
    $quangcao_url = $row2[quangcao_url];
    $quangcao_img = $row2[quangcao_img];
		$quangcaotype = intval($row2[quangcao_type]);
		
		if ($quangcaotype==1)
		$chon1="selected";
		elseif ($quangcaotype==2)
		$chon2="selected";
		else
		$chon3="selected";
		
		OpenTable();
  echo "<center><font class=\"title\"><b>Sửa quảng cáo</b></font></center><br><br>"
	."<form action=\"".$adminfile.".php\" method=\"POST\"><table><tbody><tr><td class=\"fr\" width=\"30%\"><b>Tên Web</b></td><td class=\"fr_2\">"
	."<input name=\"webname\" size=\"50\" value=\"$quangcao_web\" type=\"text\"></td></tr><tr><td class=\"fr\" width=\"30%\"><b>Link</b></td><td class=\"fr_2\">"
	."<input name=\"weburl\" size=\"50\" value=\"$quangcao_url\" type=\"text\"></td></tr><tr><td class=\"fr\" width=\"30%\"><b>Logo</b></td><td class=\"fr_2\">"
	."<input name=\"webimg\" size=\"50\" value=\"$quangcao_img\" type=\"text\"></td></tr>"
	."<tr><td class=\"fr\" width=\"30%\"><b>Vị trí quảng cáo</b></td><td class=\"fr_2\">"
	."<select name=\"quangcaotype\">"
  ."<option value=\"\">Vị trí:</option>\n"
  ."<option value=\"1\" $chon1>Trong block</option>\n"
  ."<option value=\"2\" $chon2>Bên trái</option>\n"
  ."<option value=\"3\" $chon3>Bên phải</option>\n"
	."</td></tr><tr><td class=\"fr\" colspan=\"2\" align=\"center\">"
	."<input type=\"hidden\" name=\"quangcao_id\" value=\"$quangcao_id\">"
	."<input type=\"hidden\" name=\"op\" value=\"quangcaosave\">"
	."<input type=\"submit\" value=\"SỬA LIÊN KẾT\">"
  ."</td></tr></tbody></table></form>\n";
    CloseTable();
    
    include ("../footer.php");
}

##################################################
# SAVE ADS																			 #
##################################################
function quangcaosave($quangcao_id,$webname, $weburl, $webimg,$quangcaotype) {
   global $adminfile, $prefix, $db;
   
    $webname = stripslashes(FixQuotes($webname));
    $weburl = stripslashes(FixQuotes($weburl));
    $webimg = stripslashes(FixQuotes($webimg));
    $quangcaotype = intval($quangcaotype);
    
    $db->sql_query("update ".$prefix."_quangcao set quangcao_web='$webname', quangcao_url='$weburl', quangcao_img='$webimg', quangcao_type='$quangcaotype' WHERE quangcao_id='$quangcao_id'");
      
    if (!$db) {
	exit();
    }
    
    Header("Location: ".$adminfile.".php?op=quangcaoquanly");
      
}

##################################################
# DELETE ADS																		 #
##################################################
function quangcaodel($quangcao_id) {
    global $adminfile, $prefix, $db;
    	
    	$db->sql_query("delete from ".$prefix."_quangcao where quangcao_id=$quangcao_id");
    	
	if (!$db) {
	    exit();
	}
	
	Header("Location: ".$adminfile.".php?op=quangcaoquanly");
   
}

##################################################
# CONFIG ADS																		 #
# CONFIG SAVE ADS																 #
##################################################
############################################################################
#PHẦN NÀY CHƯA CẦN LÀM VÌ MẤT CÔNG MÀ TÁC DỤNG THÌ KHÔNG ĐƯỢC BAO NHIÊU.   #
#BẠN NÀO CẢM THẤY CÓ NHỮNG CHỖ NÀO CẦN PHẢI CẤU HÌNH THÌ CỨ ĐỀ ĐẠT ĐỂ  	   #
#MÌNH THÊM VÀO TRONG CÁC PHIÊN BẢN LẦN SAU ĐƯỢC HOÀN THIỆN HƠN				  	 #
############################################################################

switch ($op){

		case "quangcaoquanly":
    quangcaoquanly();
    break;
    
    case "quangcaoadd":
    quangcaoadd($webname, $weburl, $webimg,$quangcaotype);
    break;

    case "quangcaoedit":
    quangcaoedit($quangcao_id);
    break;
    
		case "quangcaosave":
    quangcaosave($quangcao_id,$webname, $weburl, $webimg,$quangcaotype);
    break;
    
    case "quangcaodel":
    quangcaodel($quangcao_id);
    break;
        
    }

} else {
    echo "Access Denied";
}
?>